<template>
<div>
  <el-date-picker
    class="datapick"
    v-model="deviceFormData.time"
    type="daterange"
    size="mini"
    value-format=""
    :picker-options="pickerOptions"
    :default-time="['00:00:00', '23:59:59']"
    range-separator="至"
    start-placeholder="开始日期"
    end-placeholder="结束日期"
    format="yyyy-MM-dd"
    value-format="yyyy-MM-dd"
    align="right"
  >
  </el-date-picker>
  <el-tabs v-model="activeName"  @tab-click="handleClick">
    <div class="block">
      <!-- 搜索区域 -->
      <div class="search"  v-if="permissions=='1'||permissions=='2'">
        <el-form ref="form" label-width="74px" :inline="true" :model="searchList">
          <el-form-item label="姓名"><el-input size="mini" placeholder="请输入姓名" v-model="searchList.name"></el-input></el-form-item>
          <el-form-item label="学号"><el-input size="mini" placeholder="请输入学生学号" v-model="searchList.studentId"></el-input></el-form-item>
          <el-form-item label="宿舍楼"><el-input size="mini" placeholder="请输入宿舍楼" v-model="searchList.buildNo"></el-input></el-form-item>
          <el-form-item label="宿舍号"><el-input size="mini" placeholder="请输入宿舍号" v-model="searchList.dormNo"></el-input></el-form-item>
          <el-form-item label="辅导员"><el-input size="mini" placeholder="请输入辅导员姓名" v-model="searchList.counselor" :disabled="permissions=='2'"></el-input></el-form-item>
          <el-form-item label="查询条件"><el-switch
            v-model="isresetform"
            active-text="刷新"
            inactive-text="不刷新"
            @click="switchchange">
          </el-switch></el-form-item>
          <el-button type="primary" size="mini" class="el-icon-search" style="margin-top:8px" @click="gotosearch">查询</el-button>
       </el-form>
      </div>
    </div>
    <el-tab-pane label="夜不归宿" name="first"  v-if="permissions=='1'||permissions=='2'">
    <!-- 新增夜不归宿 -->
    <el-button type="primary" size="samll" class="addButton" @click="addLineNight()" v-bind:disabled="addLineShow">
      新增
    </el-button>
    <el-table
        border
        style="width: 100%"
        :show-header= false
        :data="addList"
        v-show="addLineShowNight"
        >
        <el-table-column
          label="日期"
          width="180">
          <template slot-scope="scope">
            <el-button @click="getNowDate()" size="small" type="primary" v-show="dateButton">获取当前时间</el-button>
            <span v-model="addList[0].date" v-show="!dateButton"> {{addList[0].date}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="studentName"
          label="姓名">{{addList[0].studentName}}
        </el-table-column>
        <el-table-column
          prop="studentId"
          label="学号"
          width="180">
          {{addList[0].studentId}}</el-table-column>
        <el-table-column
          prop="buildNo"
          label="楼号">
          <template slot-scope="scope"><el-select v-model="addList[0].buildNo" filterable placeholder="请选择" @change="qureyDormNo()">
              <el-option
                v-for="item in buildNoList"
                :key="item.buildNo"
                :label="item.buildNo"
                :value="item.buildNo">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="dormNo"
          label="寝室号">
          <template slot-scope="scope"><el-select v-model="addList[0].dormNo" filterable placeholder="请选择" @change="qureyBedNo()"> 
              <el-option
                v-for="item in dormNoList"
                :key="item.dormNo"
                :label="item.dormNo"
                :value="item.dormNo">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="bedNo"
          label="床位">
          <template slot-scope="scope">
            <el-select  v-model="addList[0].bedNo" filterable placeholder="请选择"  @change="qureyStudentInfo()"> 
              <el-option
                v-for="item in bedNoList"
                :key="item.bedNo"
                :label="item.bedNo"
                :value="item.bedNo"
                >
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="professional"
          label="学院班级">
          {{addList[0].professional}}
        </el-table-column>
        <el-table-column
          prop="counselor"
          label="辅导员">{{addList[0].counselor}}
        </el-table-column>
        <el-table-column
          prop="commitMan"
          label="提交者">{{addList[0].commitMan}}
        </el-table-column>
        <el-table-column
          prop="remarks"
          label="备注">
          <template slot-scope="scope">
            <el-input type="text" placeholder="请输入备注(非必填)" v-model="addList[0].remarks"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="address"
          label="操作">
          <el-button type="success" size="small" icon="el-icon-check" circle  title="提交" @click="commitAddNight()"></el-button>
          <el-button type="info" size="small" icon="el-icon-close" circle  title="取消" @click="closeAddLine()"></el-button>
        </el-table-column>
      </el-table>
      <!-- 夜不归宿 -->
      <el-table
      border
      style="width: 100%"
      :data="nightLeaList">
      <el-table-column
        prop="date"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="studentName"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="studentId"
        label="学号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="buildNo"
        label="楼号">
      </el-table-column>
      <el-table-column
        prop="dormNo"
        label="寝室号">
      </el-table-column>
      <el-table-column
        prop="bedNo"
        label="床位">
      </el-table-column>
      <el-table-column
        prop="professional"
        label="学院班级">
      </el-table-column>
      <el-table-column
        prop="counselor"
        label="辅导员">
      </el-table-column>
      <el-table-column
        prop="commitMan"
        label="提交者">
      </el-table-column>
      <el-table-column
        prop="remarks"
        label="备注">
          <template slot-scope="scope">
          <span v-show="!scope.row.isEdit">{{scope.row.remarks}}</span>
            <el-input v-show="scope.row.isEdit" type="text" placeholder="请输入备注(非必填)" v-model="commitEditList.remarks"></el-input>
          </template>
      </el-table-column>
      <el-table-column
        label="操作" prop="isTrue">
        <template slot-scope="scope">
          <span v-show="scope.row.isTrue==1">已确认</span>
          <span v-show="scope.row.isTrue==0">已删除</span>
          <el-button type="primary" round v-bind:disabled="isDisableEdit" size="mini"  v-show="!scope.row.isEdit && scope.row.isTrue == null"@click="toEdit(scope.$index,scope.row)">编辑</el-button>
          <el-button type="success" icon="el-icon-check"  circle size='mini' v-show="scope.row.isEdit" title="确认修改" @click="checkEdit(scope.row,1)"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle size='mini'  v-show="scope.row.isEdit"  title="删除" @click="checkEdit(scope.row,0)"></el-button>
          <el-button type="info" icon="el-icon-close" circle  size='mini'  v-show="scope.row.isEdit"  title="取消" @click="toCloseEdit(scope.$index,scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    
    
    <!-- 分页区域 -->
     <!--  <div class="page">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum" :page-size="pageSize" layout=" prev, pager, next, sizes, jumper" :total="total" :page-sizes="[4, 8, 10, 20]">
        </el-pagination>
      </div> -->
     
    </el-tab-pane>
    <el-tab-pane label="安全检查" name="second" v-if="permissions=='1'||permissions=='2'">
       <el-button type="primary" size="samll" class="addButton" @click="addLine()" v-bind:disabled="addLineShow">
      新增
    </el-button>
    <el-table
        border
        style="width: 100%"
        :show-header= false
        :data="addList"
        v-show="addLineShow"
        >
        <el-table-column
          label="日期"
          width="180">
          <template slot-scope="scope">
            <el-button @click="getNowDate()" size="small" type="primary" v-show="dateButton">获取当前时间</el-button>
            <span v-model="addList[0].date" v-show="!dateButton"> {{addList[0].date}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="studentName"
          label="姓名">{{addList[0].studentName}}
        </el-table-column>
        <el-table-column
          prop="studentId"
          label="学号"
          width="180">
          {{addList[0].studentId}}</el-table-column>
        <el-table-column
          prop="buildNo"
          label="楼号">
          <template slot-scope="scope"><el-select v-model="addList[0].buildNo" filterable placeholder="请选择" @change="qureyDormNo()">
              <el-option
                v-for="item in buildNoList"
                :key="item.buildNo"
                :label="item.buildNo"
                :value="item.buildNo">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="dormNo"
          label="寝室号">
          <template slot-scope="scope"><el-select v-model="addList[0].dormNo" filterable placeholder="请选择" @change="qureyBedNo()"> 
              <el-option
                v-for="item in dormNoList"
                :key="item.dormNo"
                :label="item.dormNo"
                :value="item.dormNo">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="bedNo"
          label="床位">
          <template slot-scope="scope">
            <el-select  v-model="addList[0].bedNo" filterable placeholder="请选择"  @change="qureyStudentInfo()"> 
              <el-option
                v-for="item in bedNoList"
                :key="item.bedNo"
                :label="item.bedNo"
                :value="item.bedNo"
                >
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="professional"
          label="学院班级">
          {{addList[0].professional}}
        </el-table-column>
        <el-table-column
          prop="counselor"
          label="辅导员">
          {{addList[0].counselor}}
        </el-table-column>
        <el-table-column
          prop="vioThing"
          label="违纪物品">
          <!-- <el-input placeholder="请输入违纪物品" v-model="addList[0].vioThing"></el-input> -->
          <template slot-scope="scope">
            <el-select  v-model="addList[0].vioThing" filterable placeholder="请选择"> 
              <el-option
                v-for="item in vioThingsList"
                :key="item.things"
                :label="item.things"
                :value="item.things"
                >
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="vioNum"
          label="违纪数量">
          <template slot-scope="scope">
            <el-input  placeholder="请输入物品数量" v-model="addList[0].vioNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="commitMan"
          label="提交者">{{addList[0].commitMan}}
        </el-table-column>
        <el-table-column
          prop="remarks"
          label="备注">
          <template slot-scope="scope">
            <el-input type="text" placeholder="请输入备注(非必填)" v-model="addList[0].remarks"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="address"
          label="操作">
          <el-button type="success" size="small" icon="el-icon-check" circle  title="提交" @click="commitAddSave()"></el-button>
          <el-button type="info" size="small" icon="el-icon-close" circle  title="取消" @click="closeAddLine()"></el-button>
        </el-table-column>
      </el-table>
      <el-table
        border
        style="width: 100%"
        :data="savetyList">
        <el-table-column
          prop="date"
          label="日期"
          width="180">
        </el-table-column>
        <el-table-column
          prop="studentName"
          label="姓名">
        </el-table-column>
        <el-table-column
          prop="studentId"
          label="学号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="buildNo"
          label="楼号">
        </el-table-column>
        <el-table-column
          prop="dormNo"
          label="寝室号">
        </el-table-column>
        <el-table-column
          prop="bedNo"
          label="床位">
        </el-table-column>
        <el-table-column
          prop="professional"
          label="学院班级">
        </el-table-column>
        <el-table-column
          prop="counselor"
          label="辅导员">
        </el-table-column>
        <el-table-column
          prop="vioThing"
          label="违纪物品">
        </el-table-column>
        <el-table-column
          prop="vioNum"
          label="违纪数量">
        </el-table-column>
        <el-table-column
          prop="commitMan"
          label="提交者">
        </el-table-column>
        <el-table-column
        prop="remarks"
        label="备注">
          <template slot-scope="scope">
          <span v-show="!scope.row.isEdit">{{scope.row.remarks}}</span>
            <el-input v-show="scope.row.isEdit" type="text" placeholder="请输入备注(非必填)" v-model="commitEditList.remarks"></el-input>
          </template>
      </el-table-column>
      <el-table-column
        label="操作" prop="isTrue">
        <template slot-scope="scope">
          <span v-show="scope.row.isTrue==1">已确认</span>
          <span v-show="scope.row.isTrue==0">已删除</span>
          <el-button type="primary" round v-bind:disabled="isDisableEdit" size="mini"  v-show="!scope.row.isEdit && scope.row.isTrue == null"@click="toEdit(scope.$index,scope.row)">编辑</el-button>
          <el-button type="success" icon="el-icon-check"  circle size='mini' v-show="scope.row.isEdit" title="确认修改" @click="checkEdit(scope.row,1)"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle size='mini'  v-show="scope.row.isEdit"  title="删除" @click="checkEdit(scope.row,0)"></el-button>
          <el-button type="info" icon="el-icon-close" circle  size='mini'  v-show="scope.row.isEdit"  title="取消" @click="toCloseEdit(scope.$index,scope.row)"></el-button>
        </template>
      </el-table-column>
      </el-table>
    
      
    </el-tab-pane>
    <el-tab-pane label="卫生检查" name="third" v-if="permissions=='1'||permissions=='2'">
      <!-- 新增卫生检查 -->
    <el-button type="primary" size="samll" class="addButton" @click="addLineClear()" v-bind:disabled="isShowAddButtonClear">
      新增
    </el-button>
    <el-table
        border
        style="width: 100%"
        :show-header= false
        :data="addList"
        v-show="isShowAddButtonClear"
        >
        <el-table-column
          label="日期"
          width="180">
          <template slot-scope="scope">
            <el-button @click="getNowDate()" size="small" type="primary" v-show="dateButton">获取当前时间</el-button>
            <span v-model="addList[0].date" v-show="!dateButton"> {{addList[0].date}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="studentName"
          label="姓名">{{addList[0].studentName}}
        </el-table-column>
        <el-table-column
          prop="studentId"
          label="学号"
          width="180">
          {{addList[0].studentId}}</el-table-column>
        <el-table-column
          prop="buildNo"
          label="楼号">
          <template slot-scope="scope"><el-select v-model="addList[0].buildNo" filterable placeholder="请选择" @change="qureyDormNo()">
              <el-option
                v-for="item in buildNoList"
                :key="item.buildNo"
                :label="item.buildNo"
                :value="item.buildNo">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="dormNo"
          label="寝室号">
          <template slot-scope="scope"><el-select v-model="addList[0].dormNo" filterable placeholder="请选择" @change="qureyBedNo()"> 
              <el-option
                v-for="item in dormNoList"
                :key="item.dormNo"
                :label="item.dormNo"
                :value="item.dormNo">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="bedNo"
          label="床位">
          <template slot-scope="scope">
            <el-select  v-model="addList[0].bedNo" filterable placeholder="请选择"  @change="qureyStudentInfo()"> 
              <el-option
                v-for="item in bedNoList"
                :key="item.bedNo"
                :label="item.bedNo"
                :value="item.bedNo"
                >
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="professional"
          label="学院班级">
          {{addList[0].professional}}
        </el-table-column>
        <el-table-column
          prop="counselor"
          label="辅导员">{{addList[0].counselor}}
        </el-table-column>
        <el-table-column
          prop="score"
          label="分数">{{addList[0].score}}
        </el-table-column>
        <el-table-column
          prop="commitMan"
          label="提交者">{{addList[0].commitMan}}
        </el-table-column>
        <el-table-column
          prop="remarks"
          label="备注">
          <template slot-scope="scope">
            <el-input type="text" placeholder="请输入备注(非必填)" v-model="addList[0].remarks"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="address"
          label="操作">
          <el-button type="success" size="small" icon="el-icon-check" circle  title="提交" @click="commitAddNight()"></el-button>
          <el-button type="info" size="small" icon="el-icon-close" circle  title="取消" @click="closeAddLine()"></el-button>
        </el-table-column>
      </el-table>
      <el-table
      border
      style="width: 100%"
      :data="clearList">
      <el-table-column
        prop="date"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="studentName"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="studentId"
        label="学号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="buildNo"
        label="楼号">
      </el-table-column>
      <el-table-column
        prop="dormNo"
        label="寝室号">
      </el-table-column>
      <el-table-column
        prop="bedNo"
        label="床位">
      </el-table-column>
      <el-table-column
        prop="professional"
        label="学院班级">
      </el-table-column>
      <el-table-column
        prop="counselor"
        label="辅导员">
      </el-table-column>
      <el-table-column
        prop="score"
        label="分数">
      </el-table-column>
      <el-table-column
          prop="commitMan"
          label="提交者">
      </el-table-column>
      <el-table-column
        prop="remarks"
        label="备注">
          <template slot-scope="scope">
          <span v-show="!scope.row.isEdit">{{scope.row.remarks}}</span>
            <el-input v-show="scope.row.isEdit" type="text" placeholder="请输入备注(非必填)" v-model="commitEditList.remarks"></el-input>
          </template>
      </el-table-column>
      <el-table-column
        label="操作" prop="isTrue">
        <template slot-scope="scope">
          <span v-show="scope.row.isTrue==1">已确认</span>
          <span v-show="scope.row.isTrue==0">已删除</span>
          <el-button type="primary" round v-bind:disabled="isDisableEdit" size="mini"  v-show="!scope.row.isEdit && scope.row.isTrue == null"@click="toEdit(scope.$index,scope.row)">编辑</el-button>
          <el-button type="success" icon="el-icon-check"  circle size='mini' v-show="scope.row.isEdit" title="确认修改" @click="checkEdit(scope.row,1)"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle size='mini'  v-show="scope.row.isEdit"  title="删除" @click="checkEdit(scope.row,0)"></el-button>
          <el-button type="info" icon="el-icon-close" circle  size='mini'  v-show="scope.row.isEdit"  title="取消" @click="toCloseEdit(scope.$index,scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    </el-tab-pane>
    <el-tab-pane label="违纪汇总" name="fourth">
      <el-table
      border
      style="width: 100%"
      :data="allVioList">
      <el-table-column
        prop="date"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="studentName"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="studentId"
        label="学号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="buildNo"
        label="楼号">
      </el-table-column>
      <el-table-column
        prop="dormNo"
        label="寝室号">
      </el-table-column>
      <el-table-column
        prop="bedNo"
        label="床位">
      </el-table-column>
      <el-table-column
        prop="professional"
        label="学院班级">
      </el-table-column>
      <el-table-column
        prop="counselor"
        label="辅导员">
      </el-table-column>
      <el-table-column
        label="违纪类型">
        <template slot-scope="props">
          <span v-if="props.row.vioType === '2'">
            夜不归宿
          </span>
          <span v-else-if="props.row.vioType === '1'">
            {{props.row.vioThing}}
          </span>
          <span v-else-if="props.row.vioType === '3'">
            卫生不合格
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="score"
        label="数量/分数">
        <template slot-scope="props">
          <span v-if="props.row.vioType === '1'">
            {{props.row.vioNum}}
          </span>
          <span v-else-if="props.row.vioType === '3'">
            {{props.row.score}}
          </span>
        </template>
      </el-table-column>
      
    </el-table>
    </el-tab-pane>
  </el-tabs>
  </div>
</template>
<script>
import request from "@/utils/request";
import { getPermissions,removeToken, getUserName,getUserId} from "@/utils/auth";

import { formatDate } from "@/utils/format";
export default {
  name: 'violation',
  data() {
    return {
      activeName: 'fourth',
      permissions:'',
      allVioList:[],
      nightLeaList:[],
      savetyList:[],
      clearList:[],
      buildNoList:[],
      dormNoList:[],
      bedNoList:[],
      vioThingsList:[],
      addList:[{
        date:'',
        studentName:'',
        studentId:'',
        buildNo:'',
        dormNo:'',
        bedNo:'',
        professional:'',
        counselor:'',
        vioType:'2',
        vioThing:'',
        score:'',
        vioNum:'',
        commitMan:'',
        remarks:''
        }],
      // 当前用户id
      userId: "",
      // 当前页签
      nowTab:"2",
      // 新增栏的显示与隐藏
      addLineShow: false,
      addLineShowNight:false,
      isShowAddButton: false,
      isShowAddButtonNight: false,
      isShowAddButtonClear:false,
      dateButton:true,
      // 时间选择器
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
          }]
        },
        deviceFormData:{
          time:[]
        },
        value2: [],
        searchList:{
          startTime:'',
          endTime:'',
          name:'',
          studentId:'',
          buildNo:'',
          dormNo:'',
          counselor:''
        },
        isresetform:false,
        //编辑
        isDisableEdit:false,
        // 是否可以编辑
        isEdit:true,
        commitEditList:{
        remarks:'',
        studentId:'',
        date:'',
        istrue:'',
        vioType:'',
         userId:''

      }
    };
  },
  created() {
      const that = this;
      that.getTodayDate()
  },
  mounted(){
    this.getRole()
    

  },
  methods: {
    // 浏览器窗口
    getRole(){
      this.permissions = getPermissions()
      if(this.permissions=='2'){
      this.searchList.counselor = getUserName()
      }
      this.userId = getUserId()
      console.log(this.userId);
      if (this.permissions == '3') {
      this.getAllVio()
    }
    else{
      this.getAllVio(),
    this.nighteLea(),
    this.getSavetyList(),
    this.getBuildNo(),
    this.getVioList()
    this.getClearList()
    }
    
    
    },
    handleClick(tab, event) {
      console.log(tab, event);
      if (tab.index == 0) {
        this.nowTab ='1'
      }
      if (tab.index == 1) {
        this.nowTab ='2'
      }
      if (tab.index == 2) {
        this.nowTab ='3'
      }
      if (tab.index == 3) {
        this.nowTab =''
      }
      if (this.isresetform == true){
        this.resetForm()
      }
      
    },
    switchchange(){
      this.isresetform = !this.isresetform
    },
    resetForm(){
          console.log(this.searchList);
          this.searchList.name=''
          this.searchList.startTime='',
          this.searchList.endTime='',
          this.searchList.studentId='',
          this.searchList. buildNo='',
          this.searchList.dormNo=''
          // this.searchList.counselor=''
    },
    handleSelect(key, keyPath) {
    },
    handleCommand(command) {
      if (command === "logout") {
        removeToken();
        this.$router.push("/");
      }
    },
    //获取所有违纪信息
    getAllVio(){
      if(this.permissions==3){
        var userId =this.userId
        request({
        url: "/api/violation/samedorm",
        method: "post",
        data: {
          userId:userId
        }
      }).then(res => {
        if (res.status === 200) {
          this.allVioList = res.data;
          this.allVioList.date =new Date(this.allVioList.date)
          console.log(this.allVioList);
        }
      });
      }else{
      request({
        url: "/api/violation/queryAllVioList",
        method: "post",
        data: {
          query:'',
          queryList:this.searchList
        }
      }).then(res => {
        // console.log(res);
        if (res.status === 1) {
          this.allVioList = res.list;
          this.allVioList.date =new Date(this.allVioList.date)
        }
      });
      }
    },
    // 获取夜不归宿
    nighteLea(){
      request({
        url: "/api/violation/queryAllVioList",
        method: "post",
        data: {
          query:'1',
          queryList:this.searchList
        }
      }).then(res => {
        // console.log(res);
        if (res.status === 1) {
          this.nightLeaList = res.list;
        }
      });
    },
    // 获取安全
    getSavetyList(){
      request({
        url: "/api/violation/queryAllVioList",
        method: "post",
        data: {
          query:'2',
          queryList:this.searchList
        }
      }).then(res => {
        // console.log(res);
        if (res.status === 1) {
          this.savetyList = res.list;
        }
      });
    },
    getClearList(){
      request({
        url: "/api/violation/queryAllVioList",
        method: "post",
        data: {
          query:'3',
          queryList:this.searchList
        }
      }).then(res => {
        // console.log(res);
        if (res.status === 1) {
        this.clearList = res.list;
        }
      });
    },
    // 获取当前时间
    getNowDate(row){
      this.nowDate(row),
      this.dateButton = false,
      this.addList[0].commitMan = getUserName()
    },
    nowDate(){
      var moment = require('moment');
        moment.locale('zh-cn');
        this.addList[0].date =moment().format('YYYY-MM-DD HH:mm:ss')
        // console.log("aaa"+this.addList);
    },
    // 点击新增按钮显示新增行
    addLine(){
      this.addLineShow = true,
      this.isShowAddButton = true,
      this.isShowAddButtonNight = true
    },
    addLineNight(){
      this.addLineShowNight = true,
      this.isShowAddButtonNight = true,
      this.isShowAddButton = true

    },
    addLineClear(){
      this.addLineShowClear = true,
      this.isShowAddButtonClear = true,
      this.isShowAddButton = true

    },
    //取消新增操作
    closeAddLine(){
      this.addLineShow = false,
      this.isShowAddButton = false,
      this.addLineShowNight = false,
      this.isShowAddButtonNight = false,
      this.isShowAddButtonClear = false,

      this.delAddData()
    },
    commitAddNight(){
      this.addList[0].vioType = '1'
      this.commitAdd()
    },
    commitAddSave(){
      this.addList[0].vioType = '2'
      this.commitAdd()
    },
    commitAddClear(){
      this.addList[0].vioType = '3'
      this.commitAdd()
    },
    //提交新增操作
    commitAdd(){
      this.addLineShowNight=false
      console.log(this.addList[0]);
      var addList = this.addList[0]
      request({
        url: "/api/violation/addVio",
        method: "post",
        data: addList
      }).then(res => {
        if (res.status === 1) {   
          this.delAddData()
          this.nighteLea()
          this.getSavetyList()
        }
      });
      this.addLineShow = false,
      this.isShowAddButton = false
    },
    // 清空新增数据
    delAddData(){
      this.addList=[{
        date:'',
        studentName:'',
        studentId:'',
        buildNo:'',
        dormNo:'',
        bedNo:'',
        professional:'',
        counselor:'',
        vioType:'',
        vioThing:'',
        vioNum:'',
        score:'',
        commitMan:'',
        remarks:''
      }],
      
      this.dateButton=true
    },
    // 查询是宿舍楼号
    getBuildNo(){
      request({
        url: "/api/studentInfo/getBuildNo",
        method: "post",
        data: {}
      }).then(res => {
        // console.log(res);
        if (res.msg === "查询成功") {
          this.buildNoList = res.list;
        }
      });
    },
    // 新增用户信息查询宿舍号
    qureyDormNo(){
      var _this = this
      request({
        url: "/api/studentInfo/addDormNo",
        method: "post",
        data: {
         buildNo: _this.addList[0].buildNo
        }
      }).then(res => {
        // console.log(res);
        if (res.msg === "查询成功") {
          this.dormNoList = res.list;
        }
      });
    },
    qureyBedNo(row){
      var _this = this
      request({
        url: "/api/studentInfo/addBedNo",
        method: "post",
        data: {
         buildNo: _this.addList[0].buildNo,
         dormNo: _this.addList[0].dormNo,
         isLive:'1'
        }
      }).then(res => {
        // console.log(res);
        if (res.status === 1) {
          this.bedNoList = res.list;

        }
      });
    },
    qureyStudentInfo(){
       var _this = this
       console.log(_this.addList[0].buildNo);
      request({
        url: "/api/violation/vioStudent",
        method: "post",
        data: {
          buildNo: _this.addList[0].buildNo,
         dormNo: _this.addList[0].dormNo,
         bedNo: _this.addList[0].bedNo,
        }
      }).then(res => {
        if (res.status=== 200) {
            this.addList[0].studentName = res.list[0].studentName
           this.addList[0].counselor = res.list[0].counselor
           this.addList[0].professional = res.list[0].professional
           this.addList[0].studentId = res.list[0].studentId
           this.addList[0].counselor = res.list[0].counselor
        }
      });
    },
    // 获取违纪学生信息
    /* qureyBedNo(){
      this.addList.bedNo="",
      request({
        url: "/api/studentInfo/addBedNo",
        method: "post",
        data: {
         buildNo: this.addList.buildNo,
         dormNo: this.addList.dormNo
        }
      }).then(res => {
        console.log(res);
        if (res.msg === "查询成功") {
          this.bedNoList = res.list;

        }
      });
    }, */
    // 当前时间
    getTodayDate(){
      const that = this;
      const end = new Date();
      const start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
      that.deviceFormData.time[0] = that.formatDate1(start);
      that.deviceFormData.time[1] = that.formatDate1(end);
      console.log(that.deviceFormData);
    },
    formatDate1(date) {
      var myyear = date.getFullYear();
      var mymonth = date.getMonth() + 1;
      var myweekday = date.getDate();

      if (mymonth < 10) {
        mymonth = "0" + mymonth;
      }
      if (myweekday < 10) {
        myweekday = "0" + myweekday;
      }
      return myyear + "-" + mymonth + "-" + myweekday;
    },
    //查询按钮
    gotosearch(){
      console.log(this.deviceFormData.time[0]);
      this.searchList.startTime = formatDate(new Date(this.deviceFormData.time[0]));
      this.searchList.endTime = formatDate(new Date(this.deviceFormData.time[1]));
      console.log(this.searchList.startTime);
      if (this.nowTab =='1') {
        this.nighteLea()
      }
      if (this.nowTab =='2') {
        this.getSavetyList()
      }
      if (this.nowTab =='3') {
        this.getClearList()
      }
      if (this.nowTab =='4') {
        this.getAllVio()
      }
    },
    // 查询违纪物品列表
    getVioList(){
      request({
        url: "/api/violation/vioThingsList",
        method: "post",
        data: {}
      }).then(res => {
        if (res.status=== 200) {
          this.vioThingsList = res.list
        }
      });
    },
    toEdit(index,row){
      this.$set(row, 'isEdit', true)
      this.isDisableEdit = !this.isDisableEdit
    },
    // 确认编辑
    checkEdit(row,istrue){
      this.commitEditList.studentId = row.studentId,
      this.commitEditList.date = row.date,
      this.commitEditList.istrue = istrue,
      this.commitEditList.vioType = row.vioType
      var commitEditList =this.commitEditList

      console.log(commitEditList);
       this.$confirm('此操作修改此备注信息', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          request({
            url: "/api/violation/editVio",
            method: "post",
            data: commitEditList
          }).then(res => { 
            console.log(res);
            if (res.status === 200) {
               this.$set(row, 'isEdit', false)
              this.isDisableEdit = !this.isDisableEdit
              this.getAllVio(),
              this.nighteLea(),
              this.getSavetyList(),
              this.getClearList()
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
            }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消重置操作'
          });          
        });
      
             

    },
     toCloseEdit(index,row) {
      this.$set(row, 'isEdit', false)
      this.isDisableEdit = !this.isDisableEdit
      this.formChange = true
    },
  }
}

</script>
<style lang="scss" scoped>
.datapick {
  position: fixed;
  width: 210px!important;
  right: 30px;
  z-index: 100;
}
/* .block {
  margin-bottom: 10px;
} */
.addButton{
  float: right;
  margin-top: -10px;
}
.page {
  width: 30%;
  margin: auto;
  margin-top: 10px;
}
</style>
